package com.ss.android.account.v2.view;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;

import com.ss.android.account.customview.a.a;
import com.ss.android.account.customview.a.c;
import com.ss.android.account.customview.a.d;
import com.ss.android.account.customview.slidingdrawer.SuperSlidingDrawer;
import com.ss.android.article.browser.R;
import com.ss.android.common.util.ImmersedStatusBarHelper.ImmersedStatusBarConfig;
import com.ss.android.messagebus.Subscriber;
import com.ss.android.messagebus.SubscriptionRouter;
import com.ss.android.newmedia.activity.BaseActivity;

import im.quar.autolayout.utils.AutoLayoutHelper;
import im.quar.autolayout.utils.AutoUtils;

public class AccountLoginActivity extends BaseActivity {
    public enum AccountAction {
        LOGIN
    }


    SuperSlidingDrawer a;
    String b;
    Handler c;
    public boolean d;
    boolean e;
    private ImageView f;
    private View g;
    private a h;
    private AccountAction i;
    private String j;
    private boolean k;
    private boolean l;
    private FragmentManager m;

    public AccountLoginActivity() {

        this.l = false;
    }

    final void a() {
        CharSequence v2_2;
        android.support.design.a.a(((Context) this), "cancel_register_dialog_show", this.b);
        android.support.design.a.m(((Context) this));
        com.ss.android.account.customview.a.a.a$a v0 = new com.ss.android.account.customview.a.a.a$a(((Context) this));
        v0.b = this.getString(com.ss.android.article.browser.R.string.account_confirm_give_up_register);
        String v1 = this.getString(com.ss.android.article.browser.R.string.account_continue_register);
        g v2 = new g(this);
        v0.c = ((CharSequence) v1);
        v0.e = ((DialogInterface.OnClickListener) v2);
        v1 = this.getString(com.ss.android.article.browser.R.string.account_give_up);
        f v2_1 = new f(this);
        v0.d = ((CharSequence) v1);
        v0.f = ((DialogInterface.OnClickListener) v2_1);
        a v1_1 = new a(v0.mContext);
        v1_1.mImageClose.setVisibility(View.GONE);
        v1_1.mTvMessage.setText(v0.b);
        if (!TextUtils.isEmpty(v0.c) || v0.e != null) {
            v2_2 = v0.c;
            DialogInterface.OnClickListener v3 = v0.e;
            if (v1_1.mBtnPositive.getVisibility() != View.VISIBLE) {
                v1_1.mBtnPositive.setVisibility(View.VISIBLE);
            }

            v1_1.mBtnPositive.setText(v2_2);
            v1_1.mBtnPositive.setOnClickListener(new c(v1_1, v3));
        }

        if (!TextUtils.isEmpty(v0.d) || v0.f != null) {
            v2_2 = v0.d;
            DialogInterface.OnClickListener v0_1 = v0.f;
            if (v1_1.mBtnNegative.getVisibility() != View.VISIBLE) {
                v1_1.mBtnNegative.setVisibility(View.VISIBLE);
            }

            v1_1.mBtnNegative.setText(v2_2);
            v1_1.mBtnNegative.setOnClickListener(new d(v1_1, v0_1));
        }

        this.h = v1_1;
        this.h.show();
    }

    final void b() {
        if (this.m != null && ((this.m.findFragmentById(com.ss.android.article.browser.R.id.content) instanceof h))) {
            android.support.design.a.a(((Context) this), "mobile_login_close", this.b);
        }
    }

    public ImmersedStatusBarConfig getImmersedStatusBarConfig() {
        return new ImmersedStatusBarConfig().setStatusBarColor(com.ss.android.article.browser.R.color.status_bar_color_detail);
    }

    public void onBackPressed() {
        if (this.m.popBackStackImmediate()) {
            SubscriptionRouter.c(new com.ss.android.account.bus.event.a());
        } else if (this.e) {
            this.a();
        } else {
            this.a.animateClose();
            this.b();
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        int v4 = -1;
        int v6 = R.id.content;
        this.mActivityAnimType = 1;
        super.onCreate(savedInstanceState);
        SubscriptionRouter.addSubscriber(this);
        this.i = (AccountAction) this.getIntent().getSerializableExtra("extra_account_type");
        if (this.i == null) {
            this.i = AccountAction.LOGIN;
        }

        this.j = this.getIntent().getStringExtra("extra_title_type");
        this.b = this.getIntent().getStringExtra("extra_source");
        this.getIntent().getBooleanExtra("extra_from_dialog", false);
        this.k = android.support.design.a.l(((Context) this));
        this.c = new Handler();
        this.setContentView(com.ss.android.article.browser.R.layout.account_login_activity);
        this.getWindow().getAttributes().width = v4;
        this.getWindow().getAttributes().height = v4;
        this.a = (SuperSlidingDrawer) this.findViewById(R.id.drawer);
        this.f = (ImageView) this.findViewById(R.id.img_close);
        this.g = this.findViewById(v6);
        this.a.setExpandedOffset(AutoUtils.scaleValue(0));
        this.a.setClosedOnTouchOutside(true);
        this.m = this.getSupportFragmentManager();
        Fragment v0 = this.m.findFragmentById(v6);
        if (v0 == null) {
            h v3 = new h();
            if (!this.l) {
                String v4_1 = "mobile_login_show";
                String v5 = this.b;
                int v0_1 = this.k ? 1 : 0;
                android.support.design.a.a(((Context) this), "register_new", v4_1, v5, v0_1);
            }

            this.l = true;
            Bundle v0_2 = new Bundle();
            v0_2.putString("extra_title_type", this.j);
            v0_2.putString("extra_source", this.b);
            v0_2.putBoolean("is_last_fragment", true);
            ((Fragment) v3).setArguments(v0_2);
            h v0_3 = v3;
        }

        FragmentTransaction v1 = this.m.beginTransaction();
        v1.replace(v6, v0);
        v1.commit();
        this.getWindow().getDecorView().postDelayed(new com.ss.android.account.v2.view.a(this), 100);
        this.a.setOnDrawerCloseListener(new com.ss.android.account.customview.slidingdrawer.SuperSlidingDrawer.b(this));
        this.a.setOnDrawerScrollListener(new com.ss.android.account.customview.slidingdrawer.SuperSlidingDrawer.c(this));
        this.f.setOnTouchListener(new com.ss.android.account.v2.view.b(this));
        this.f.setOnClickListener(new com.ss.android.account.v2.view.c(this));
        this.g.setOnTouchListener(new e(this));
    }

    public View onCreateView(String arg2, Context arg3, AttributeSet arg4) {
        View v0 = AutoLayoutHelper.createAutoLayoutView(arg2, arg3, arg4);
        if (v0 == null) {
            v0 = super.onCreateView(arg2, arg3, arg4);
        }

        return v0;
    }

    public void onDestroy() {
        super.onDestroy();
        SubscriptionRouter.removeSubscriber(this);
        if (this.h != null && (this.h.isShowing())) {
            this.h.dismiss();
        }
    }

    @Subscriber
    public void onFinishEvent(com.ss.android.account.bus.event.d arg3) {
        if (arg3.a) {
            this.a.animateClose();
        } else if (Build.VERSION.SDK_INT >= 21) {
            this.finishAfterTransition();
        } else {
            this.finish();
        }
    }

    @Subscriber
    public void onModifyProfileEvent(com.ss.android.account.bus.event.e arg1) {
    }

    @Subscriber
    public void onStartInputEvent(com.ss.android.account.bus.event.f arg2) {
        this.e = arg2.a;
    }
}

